package com.yupi.springbootinit.model.vo;

import com.google.gson.Gson;
import com.yupi.springbootinit.model.entity.Book;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

/**
 * 帖子视图
 *
 * @author wzh
 */
@Data
public class BookVO implements Serializable {

    private final static Gson GSON = new Gson();

    private Integer id;

    /**
     * 书本名称
     */
    private String name;

    /**
     * 书本封面图片
     */
    private String coverImg;

    /**
     * 书本摘要
     */
    private String summary;

    /**
     * 书本单本价格
     */
    private Double price;

    /**
     * 库存
     */
    private Integer Inventory;

    /**
     * 包装类转对象
     *
     * @param bookVO
     * @return
     */
    public static Book voToObj(BookVO bookVO) {
        if (bookVO == null) {
            return null;
        }
        Book book = new Book();
        BeanUtils.copyProperties(bookVO, book);
        return book;
    }

    /**
     * 对象转包装类
     *
     * @param book
     * @return
     */
    public static BookVO objToVo(Book book) {
        if (book == null) {
            return null;
        }
        BookVO bookVO = new BookVO();
        BeanUtils.copyProperties(book, bookVO);
        return bookVO;
    }
}
